home *** CD-ROM | disk | FTP | other *** search
/ The Original Shareware 1.1 / The Original Shareware (WeMake CDs)(Volume 1.1)(CDs, Inc)(1993).iso / 19 / jbcomm12.zip / JBCOMM12.DOC < prev    next >
Text File  |  1980-01-01  |  36KB  |  1,165 lines

  1.  
  2. JBCOMM: v1.2 by Jim Berg, (c)Copyright 1988 
  3.  
  4. The following procedures and functions are to assist the general 
  5. public with communications programming in Turbo Pascal v4.0.  Feel 
  6. free to use these routines in your private programs or programs 
  7. intended for the Public Domain.  If you intend to use these routines 
  8. in a program that you will receive money for, be it Shareware, 
  9. Commercial, or part of your professional program library, you must 
  10. send $15 to: 
  11.  
  12. Jim Berg 
  13. 650 Minnetonka Highland Lane 
  14. Long Lake, MN 55356 
  15.  
  16. If you find any bugs or have any suggestions, please feel free to 
  17. write, or leave me a message on Terrapin Station, (612)623-0152. 
  18.  
  19.              ********* DISCLAIMER ************* 
  20.  
  21. If something goes wrong with your hardware while using this library, 
  22. I hereby free myself from any liability with this disclaimer.  As far 
  23. as I know, these routines work.  If something does go wrong, please 
  24. contact me anyway so I may attempt to fix the program. 
  25.  
  26.  
  27.  
  28. Name:     porttype 
  29.  
  30. Usage:    cp : porttype; 
  31.  
  32. Description: 
  33.  
  34.           type porttype = (com1, com2); 
  35.  
  36.           This is the type declaration for com port numbers.  JBCOMM 
  37.           only supports COM1 and COM2 for now, but it will support 
  38.           simultaneous operation. 
  39.  
  40.  
  41. Name:     parityt 
  42.  
  43. Usage:    parity  : parityt; 
  44.  
  45. Description: 
  46.  
  47.           type parityt = (p_none,p_even,p_odd,p_even_stick,p_odd_stick); 
  48.  
  49.           This is the type declaration for parity.  See c_set_uart for 
  50.           more information on parity.  I won't describe the last two since 
  51.           those who know what they can be used for already know enough not 
  52.           to have it explained. 
  53.  
  54.  
  55.  
  56. Name:     comstr 
  57.  
  58. Usage:    outstr  : comstr; 
  59.  
  60. Description: 
  61.  
  62.           type comstr = string[255]; 
  63.  
  64.           Just a string of length 255 for your convenience.  Type String is 
  65.           just as good. 
  66.  
  67.  
  68.  
  69. Name:     checkstr 
  70.  
  71. Usage:    checklist  : array [1..n] of checkstr; 
  72.  
  73. Description: 
  74.  
  75.           type checkstr = string[80]; 
  76.  
  77.           See c_waitsn. 
  78.  
  79.  
  80. Name:     com_info_rec 
  81.  
  82. Usage:    info : com_info_rec; 
  83.  
  84. Description: 
  85.  
  86.           type 
  87.             com_info_rec = record 
  88.                              offset,            Base address of serial port. 
  89.                              speed   : word;    Current speed setting. 
  90.                              parity  : parityt; Current Parity Setting. 
  91.                              data,              Current Data size. 
  92.                              stops   : byte;    Current Stop bits. 
  93.                              active,            TRUE if port is active. 
  94.                              ints_on : boolean  TRUE if interrupts are active. 
  95.                            end; 
  96.  
  97.           See c_port_info and accompanying program example. 
  98.  
  99.  
  100.  
  101. Name:     ESC_ON 
  102.  
  103. Usage:    ESC_ON:=TRUE; or ESC_ON:=FALSE; 
  104.  
  105. Description: 
  106.  
  107.           var ESC_ON : boolean; 
  108.  
  109.           If ESC_ON is set to TRUE, it will allow you to exit out of 
  110.           c_getb and c_waitsn if the user hits ESC.  The default is 
  111.           ESC_ON:=TRUE. 
  112.  
  113.           See c_getb and c_waitsn. 
  114.  
  115.  
  116. Name:     c_set_speed 
  117.  
  118. Usage: 
  119.  
  120.           procedure c_set_speed  (cp       : porttype; 
  121.                                   speed    : word      ); 
  122. Description: 
  123.  
  124.           C_set_speed will set the current speed that your serial 
  125.           port will operate at. 
  126.  
  127. Returns:  Nothing 
  128.  
  129. Example: 
  130.           If you want to set COM1 to operation at 2400 baud, you 
  131.           would use it the following way: 
  132.  
  133.             c_set_speed(com1,2400); 
  134.  
  135.  
  136.  
  137. Name:     c_set_uart 
  138.  
  139. Usage: 
  140.  
  141.           procedure c_set_uart   (cp       : porttype; 
  142.                                   parity   : parityt; 
  143.                                   data, 
  144.                                   stops    : byte    ); 
  145.  
  146. Description: 
  147.  
  148.           C_set_uart sets the current operating format of the serial 
  149.           port.  This includes the parity, data size, and stop bits 
  150.           used. 
  151.  
  152.           Data Bits explained: 
  153.  
  154.           Most BBSes you call allow you to download binary files.  These 
  155.           files are made up of a byte which are 8 bits wide.  In order 
  156.           for your program to download these types of files, you have to 
  157.           set your serial port for 8 data bits.  If you are calling a board 
  158.           that only allows text transfers because it only uses the first 
  159.           128 characters of the ASCII set, you may want to only use 7 data 
  160.           bits, since that is all that is required for this type of use. 
  161.           Anything less than 7 is very uncommon. 
  162.  
  163.           Parity explained: 
  164.  
  165.           Parity is a very simple way of doing error correction.  If you 
  166.           were to select EVEN parity, this means that it will send an equal 
  167.           number of 1 bits as it does 0 bits.  If you receive a character 
  168.           that has more 1 bits, or more 0 bits than its opposite, they you 
  169.           can assume that the character was sent wrong.  The serial port 
  170.           will set some bits in the Line Status Register to inform you of 
  171.           these type of errors. 
  172.  
  173.           ODD is the opposite of EVEN obviously. This means that an odd 
  174.           number of bits will be sent. 
  175.  
  176.           NONE means that there is no parity at all.  This has to be used if 
  177.           you are using 8 data bits. 
  178.  
  179.           Stop bits explained: 
  180.  
  181.           A stop bit tells when a character is finished.  There is 
  182.           no real difference between 1 and 2, but most people use 1. 
  183.  Returns:  Nothing 
  184.  
  185. Example: 
  186.           Say you wanted to write a program to call your local Opus board 
  187.           and you wanted to get all of the special text graphic characters 
  188.           and be able to download a binary game.  You would then have to 
  189.           set your serial port 1 to use 8 data bits, No Parity, and 1 stop 
  190.           bit.  To do this you would use: 
  191.  
  192.             c_set_uart(com1,p_none,8,1); 
  193.  
  194.  
  195.  
  196. Name:     c_open 
  197.  
  198. Usage: 
  199.  
  200.           procedure c_open       (cp       : porttype; 
  201.                                   speed    : word; 
  202.                                   parity   : parityt; 
  203.                                   data, 
  204.                                   stops    : byte; 
  205.                                   ibuffs, 
  206.                                   obuffs   : word     ); 
  207.  
  208. Description: 
  209.  
  210.          C_open starts the ball rolling for communications.  It sets 
  211.          up the serial port to use interrupts and sets the size of 
  212.          the input buffer and output buffer.  You should call this 
  213.          procedure before using any of the other communication 
  214.          routines.  If a command can be used without calling this 
  215.          first, I will let you know. 
  216.  
  217.          Speed, parity, data and stops are pretty much explained above. 
  218.          C_open calls those routines.  IBUFFS and OBUFFS are the only 
  219.          things really new here.  JBCOMM uses both an output and input 
  220.          buffer. 
  221.  
  222.          If your program does a lot of extra things before grabbing the 
  223.          character from the serial port, that character may be lost if 
  224.          you do not grab it before a new character comes in.  To get 
  225.          around this JBCOMM uses the ability of the serial port to cause 
  226.          and interrupt.  What this means is that when a character is 
  227.          received, the computer will save your spot in the program, then 
  228.          jump automatically to a routine to grab the character and then 
  229.          puts that character into a buffer to store it until you need it. 
  230.          This is what IBUFFS is for. It sets aside the number of bytes you 
  231.          specify for an input buffer. 
  232.  
  233.          The serial port also has the ability to cause an interrupt when 
  234.          its transmit register becomes empty.  This makes it possible 
  235.          for you to load characters into a buffer and the interrupt routine 
  236.          will send them when it is able.  This makes it so you are not 
  237.          always having to wait for your character to be sent.  OBUFFS is 
  238.          used to tell JBCOMM how much space to set aside for your output 
  239.          buffer. 
  240.  
  241. Example: 
  242.          You want to communicate with an Opus system and you want an input          buffer of 4096 bytes and an output buffer of 256 bytes.  You would 
  243.          then use. 
  244.  
  245.            c_open(com1,2400,p_none,8,1,4096,256); 
  246.  
  247.  
  248.  
  249. Name:    c_close 
  250.  
  251. Usage: 
  252.  
  253.          procedure c_close      (cp       : porttype; 
  254.                                  dropdtr  : boolean  ); 
  255.  
  256. Description: 
  257.  
  258.          C_close turns off interrupts and releases memory reserved with 
  259.          c_open.  See c_open.  Dropdtr tells whether you want to leave 
  260.          the port active, or to turn it off completely.  If you leave 
  261.          the port active by passing dropdtr as FALSE, you can leave your 
  262.          program without hanging up or disconnecting.  This may be useful 
  263.          if you are writing a BBS that uses doors, or if you want to write 
  264.          a COMM program that uses external protocols.  When you come back 
  265.          into the program, you can do another call to c_open. 
  266.  
  267. Returns: Nothing. 
  268.  
  269. Example: 
  270.  
  271.          You are all done with communications and you want to shutdown the 
  272.          serial port and interrupts.  You would then use. 
  273.  
  274.            c_close(com1,TRUE); 
  275.  
  276.          You want to execute or leave your program to run a program that 
  277.          has its own communication handler so you want to turn off your 
  278.          interrupts but leave the port active.  You would then use. 
  279.  
  280.            c_close(com1,FALSE); 
  281.  
  282.  
  283.  
  284. Name:    c_inready 
  285.  
  286. Usage: 
  287.  
  288.          function  c_inready( cp : porttype ) : word; 
  289.  
  290. Description: 
  291.  
  292.          C_inready is a function that returns the number of characters 
  293.          waiting in the input buffer. 
  294.  
  295. Returns: Number of characters waiting to be read in input buffer. 
  296.  
  297. Example: 
  298.  
  299.          C_inready can be used much like Keypressed.  C_inready returns 
  300.          more information however.  If you want to use it just like 
  301.          Keypressed, you can use. 
  302.  
  303.            if c_inready(com1)>0 then { get character from buffer} 
  304.  
  305.          C_inready can also be used to wait for a certain number of 
  306.          characters are in the buffer before you do something.  Say 
  307.          you needed to wait for 30 characters, then you would use. 
  308.  
  309.            repeat until c_inready(com1)>=30; 
  310.  
  311.  
  312.  
  313. Name:    c_outready 
  314.  
  315. Usage: 
  316.  
  317.          function  c_outready( cp :porttype ):word; 
  318.  
  319. Description: 
  320.  
  321.          Will return the number of characters waiting in the output 
  322.          buffer to be sent.  This is much like c_inready except it 
  323.          is for the outgoing characters. 
  324.  
  325. Returns: Number of characters waiting in output buffer. 
  326.  
  327. Example: 
  328.  
  329.          C_outready can be useful for monitoring how communications are 
  330.          going, or if you don't want to overflow the outgoing buffer. 
  331.  
  332.          You could use it if you want to make sure you don't try to add 
  333.          more characters to the output buffer if it is already half full. 
  334.          Say you have a 1k output buffer, you could use. 
  335.  
  336.            repeat until c_outready(com1)<512; 
  337.            {  Send characters } 
  338.  
  339.  
  340.  
  341. Name:    c_putc 
  342.  
  343. Usage: 
  344.  
  345.          procedure c_putc(cp : porttype; 
  346.                           ch : char     ); 
  347.  
  348. Description: 
  349.  
  350.          Sends character ch out through the serial port.  If the buffer 
  351.          is full, it will wait 2 seconds for space to become available 
  352.          and then exit after the 2 seconds.  It would be best to check 
  353.          the port with c_outready to make sure room is available so 
  354.          characters wont be lost. 
  355.  
  356. Returns: Nothing. 
  357.  
  358. Example: 
  359.  
  360.          Use it if you simply want to send a character through the serial 
  361.          port. 
  362.  
  363.            c_putc(com1,^M); 
  364.  
  365.          The above sends a carriage return through the serial port. 
  366.  
  367.  
  368.  
  369. Name:    c_insertc 
  370.  
  371. Usage: 
  372.  
  373.          procedure c_insertc(cp : porttype; 
  374.                              ch : char      ); 
  375.  
  376. Description: 
  377.  
  378.          This procedure will put a character in the input buffer as if 
  379.          it were received from the serial port. 
  380.  
  381. Returns: Nothing. 
  382.  
  383. Example: 
  384.  
  385.          C_insertc has an advanced usage.  I use it for a multi-user 
  386.          BBS I am working on.  I have several tasks running at the same 
  387.          time and one of them is a local sysop task.  What it does is to 
  388.          monitor the keyboard to see if a normal key has been pressed, and 
  389.          if one is, it grabs the character and inserts it into input buffer 
  390.          of BBS a may want to echo my keyboard with.  If it is a function 
  391.          key, I just execute the sysop command that goes with it.  It is 
  392.          something like this. 
  393.  
  394.            var ch          : char; 
  395.                active_port : porttype; 
  396.  
  397.            begin 
  398.              repeat 
  399.                if keypressed then 
  400.                begin 
  401.                  ch:=readkey; 
  402.                  if ch=#0 then 
  403.                  begin 
  404.                    ch:=readkey; 
  405.                    case ch of 
  406.                      #59:{function key 1 thing}; 
  407.                      #60:{function key 2 thing}; 
  408.                      . . . 
  409.                    end 
  410.                  end 
  411.                  else c_insertc(active_port,ch) 
  412.                end 
  413.              until {whatever is needed to exit}; 
  414.            end. 
  415.           When the character is inserted, it will be read from the 
  416.          serial port as if it came over the modem or something. 
  417.          This is great for echoing keyboards. 
  418.  
  419.  
  420.  
  421. Name:    c_inserts 
  422.  
  423. Usage: 
  424.  
  425.          procedure c_inserts(cp       : porttype; 
  426.                              outstr   : comstr   ); 
  427.  
  428. Description: 
  429.  
  430.          This does pretty much the same as c_insertc except that it 
  431.          sends a whole string rather than a single character.  If 
  432.          you put a | in the string, it will be interpreted as a 
  433.          carriage return. 
  434.  
  435. Returns: Nothing. 
  436.  
  437. Example: 
  438.  
  439.          The example is pretty much the same as for c_insertc except 
  440.          it can be used to fool your program into thinking a certain 
  441.          string has been sent.  I use it to fool the modem into thinking 
  442.          a CONNECT has been sent. 
  443.  
  444.            c_inserts(com1,'CONNECT|'#10); 
  445.  
  446.  
  447.  
  448. Name:     c_getc 
  449.  
  450. Usage: 
  451.  
  452.           function c_getc(cp : porttype ) : char; 
  453.  
  454. Description: 
  455.  
  456.           Gets a character from the input buffer.  This is much like 
  457.           readkey except it is for the serial port.  If character is 
  458.           not in input buffer, it will wait for a character to be 
  459.           available. 
  460.  
  461. Returns:  Character that has been received by serial port and stored 
  462.           in input buffer. 
  463.  
  464. Example: 
  465.           This is pretty basic.  Use it when you want to get a character 
  466.           from the serial port. 
  467.  
  468.             var ch : char; 
  469.  
  470.             begin 
  471.               ... 
  472.               ch:=c_getc(com1); 
  473.             end; 
  474.  
  475.  
  476.  
  477. Name:     c_peekc 
  478.  
  479. Usage: 
  480.  
  481.           function  c_peekc(cp : porttype ) : char; 
  482.  
  483. Description: 
  484.  
  485.           This is much like c_getc except that it will return the character 
  486.           waiting in the input buffer, but will not remove it.  It will 
  487.           allow you to "peek" at the character before you "get" the character. 
  488.  
  489. Returns:  It will return the value of the next character waiting in input 
  490.           buffer. 
  491.  
  492. Example: 
  493.  
  494.           Use it to watch incoming characters and dispose of unwanted 
  495.           characters until the one you want is found.  Maybe there is 
  496.           a string that begins with and ESC that you want to get, but 
  497.           you don't want any of the characters before the escape.  You 
  498.           could use 
  499.  
  500.             var ch : char; 
  501.  
  502.             begin 
  503.               . . . 
  504.               while peekc(com1)<>#27 then ch:=c_getc(com1); 
  505.               . . . 
  506.             end. 
  507.  
  508.           Yes, I know, this isn't the best example, but it does have a 
  509.           use.  The keyboard BIOS has something similar. 
  510.  
  511. Name:     c_flush_in 
  512.  
  513. Usage: 
  514.  
  515.           procedure c_flush_in(cp : porttype ); 
  516.  
  517. Description: 
  518.  
  519.           Clears the input buffer.  Removes characters that may be 
  520.           waiting in the input buffer. 
  521.  
  522. Returns:  Nothing.  
  523. Example: 
  524.  
  525.           In an Xmodem transfer you may get more characters then you 
  526.           wanted and the extra characters are most likely unwanted 
  527.           so you would use c_flush_in to clear the input buffer. 
  528.  
  529.             c_flush_in(com1); 
  530.  
  531.  
  532.  
  533. Name:     c_flush_out 
  534.  
  535. Usage: 
  536.  
  537.           procedure c_flush_out(cp : porttype ); 
  538.  
  539. Description: 
  540.  
  541.           Clears the output buffer of any characters that have not been 
  542.           sent yet. 
  543.  
  544. Returns:  Nothing. 
  545.  
  546. Example: 
  547.           If you are sending out a file and you receive a ^C to cancel it, 
  548.           you may want to flush the buffer to make it act more quickly. 
  549.  
  550.             c_flush_out(com1); 
  551.  
  552.  
  553.  
  554. Name:     c_carrier 
  555.  
  556. Usage: 
  557.  
  558.           function c_carrier(cp : porttype ):boolean; 
  559.  
  560. Description: 
  561.  
  562.           Tells you if your serial port detects that a carrier is present. 
  563.  
  564. Returns:  TRUE if there is a carrier present. 
  565.  
  566. Example: 
  567.  
  568.           In a BBS program, this would be used to monitor whether someone 
  569.           is still online, or if they hangup. 
  570.  
  571.             if c_carrier(com1) then 
  572.               {person is still connected} 
  573.             else 
  574.               {person has hung up} 
  575.  
  576.  
  577.  
  578. Name:     c_toggle_DTR 
  579.  
  580. Usage: 
  581.  
  582.           procedure c_toggle_DTR (cp : porttype ); 
  583.  
  584. Description: 
  585.  
  586.           Turn DTR bit on if it is off, or off if it is on. 
  587.  
  588. Returns:  Nothing. 
  589.  
  590. Example: 
  591.  
  592.           The DTR is what keeps a port active.  When you open the 
  593.           serial port the DTR is set on.  If you wanted to disconnect 
  594.           someone, you would clear the DTR to off for a certain amount 
  595.           of time, then turn it back on. 
  596.  
  597.             c_toggle_DTR(com1); 
  598.             delay(500); {half second} 
  599.             c_toggle_DTR(com1); 
  600.  
  601.           NOTE:  This will not work correctly if your modem is set so 
  602.           that the DTR is always on. 
  603.  
  604.  
  605.  
  606. Name:     c_send_break 
  607.  
  608. Usage: 
  609.  
  610.           procedure c_send_break (cp       : porttype; 
  611.                                   duration : word     ); 
  612.  
  613. Description: 
  614.  
  615.           This sends a break signal over the serial port for 
  616.           duration hundreds of a second. 
  617.  
  618. Returns:  Nothing. 
  619.  
  620. Example: 
  621.           Sometimes certain systems require you to send a break 
  622.           signal to stop something, or to disconnect properly. 
  623.  
  624.             c_send_break(com1,100); 
  625.  
  626.           The above example sends a break signal for 1 second. 
  627.  
  628.  
  629.  
  630. Name:     c_puts 
  631.  
  632. Usage: 
  633.           procedure c_puts(cp       : porttype; 
  634.                            outstr   : comstr   ); 
  635.  
  636. Description: 
  637.  
  638.           This sends a string out through the serial port.  A | is 
  639.           sent as a carriage return and a ~ is used as a 1/4 second 
  640.           delay.  This is a lot like a lot of terminal init strings. 
  641.  
  642. Returns:  Nothing. 
  643.  
  644. Example: 
  645.  
  646.           Use this to send init strings or dialing commands. 
  647.  
  648.             c_puts(com1,'ATDT 555-5555|~~~'); 
  649.  
  650.           The above sends the dialing command followed by a carriage 
  651.           return and a 3 quarters of a second delay. 
  652.  
  653.  
  654.  
  655. Name:     c_getb 
  656.  
  657. Usage: 
  658.           function  c_getb(cp       : porttype; 
  659.                            timeout  : word     ) : integer; 
  660.  
  661. Description: 
  662.  
  663.           This waits timeout hundreds of a second for a character. 
  664.  
  665. Returns:  ASCII value character received, or a -1 if it times out, or 
  666.           a -2 if ESC is hit. 
  667.  
  668. Example: 
  669.  
  670.           Use this for download procedures.  There are times when you 
  671.           have to wait a certain amount of time for a character, and 
  672.           if it doesn't arrive, you return and error. 
  673.  
  674.             var inch : integer; 
  675.  
  676.             begin 
  677.               . . . 
  678.               inch:=c_getb(com1,100);  { Wait 1 second for character} 
  679.               if inch=-1 then 
  680.                 writeln('Timeout') 
  681.               else 
  682.               begin 
  683.                 {chr(lo(inch)) equals character you received.'} 
  684.               end 
  685.             end; 
  686.  
  687.  
  688.  
  689. Name:     c_waits 
  690.  
  691. Usage: 
  692.  
  693.           function  c_waits(cp       : porttype; 
  694.                             chkstr   : checkstr; 
  695.                             timeout  : word     ) : boolean; 
  696.  
  697. Description: 
  698.  
  699.           This function will wait timeout hundreds of a second for 
  700.           string chkstr to be received from the serial port. 
  701.  
  702. Returns:  TRUE if string is received.  FALSE if it times out. 
  703.  
  704. Example: 
  705.  
  706.           Sometimes you may want to wait for a certain string to be 
  707.           returned through the serial port.  I had to write a program 
  708.           once that checked to see if the modem supported 2400 baud or 
  709.           not.  The only way I could check was to set the serial port for 
  710.           2400 baud, enter an AT <CR>, and wait to see if it returned OK. 
  711.           If it didn't, I knew it didn't like 2400 baud. 
  712.  
  713.             c_set_speed(com1,2400); 
  714.             c_puts(com1,'AT|~'); 
  715.             if c_waits(com1,'OK',500) then 
  716.               writeln('Modem supports 2400 baud.') 
  717.             else 
  718.               writeln('Modem doesn''t support 2400 baud.'); 
  719.  
  720.           NOTE:  Some modems will communicate with the serial port at speeds 
  721.           that the modem does not support. 
  722.  
  723.  
  724.  
  725. Name:     c_waitsn 
  726.  
  727. Usage: 
  728.  
  729.           function  c_waitsn(cp       : porttype; 
  730.                              var clst;{:array[1..n] of checkstr} 
  731.                              n        : byte; 
  732.                              timeout  : word     ) : integer; 
  733.  
  734. Description: 
  735.  
  736.           This will wait timeout hundreds of a second for a string 
  737.           in clst to be returned from the modem.  n tells you the 
  738.           number of strings in clst. 
  739.  
  740. Returns:  -2 if ESC is hit, -1 if it times out, or the number of the 
  741.           string that matched. 
  742.  
  743. Example: 
  744.  
  745.           This is one of the most useful commands of JBCOMM.  Use it for 
  746.           autodialing. 
  747.  
  748.           var  checklist : array [1..5] of checkstr; 
  749.                result    : integer; 
  750.  
  751.           begin 
  752.             . . . 
  753.             checklist[1]:='CONNECT'#13#10; 
  754.             checklist[2]:='CONNECT 1200'#13#10; 
  755.             checklist[3]:='CONNECT 2400'#13#10; 
  756.             checklist[4]:='NO CARRIER'#13#10; 
  757.             checklist[5]:='BUSY'#13#10; 
  758.             repeat 
  759.               c_puts(com1,'ATDT 555-5555|~~'); 
  760.               result:=c_waitsn(com1,checklist,5,6000); 
  761.               case result of 
  762.                -2:writeln('Dialing aborted'); 
  763.                -1:writeln('Timeout'); 
  764.                 1:writeln('Connected at 300 baud'); 
  765.                 2:writeln('Connected at 1200 baud'); 
  766.                 3:writeln('Connected at 2400 baud'); 
  767.                 4:writeln('No Carrier'); 
  768.                 5:writeln('Busy') 
  769.               end; 
  770.             until ((result<4) and (result>0)) or (result=-1); 
  771.             . . .           end. 
  772.  
  773.  
  774.  
  775. Name:    c_get_stream 
  776.  
  777. Usage: 
  778.          function  c_get_stream (cp       : porttype; 
  779.                                  var getbuf; 
  780.                                  n        : word     ) : word; 
  781.  
  782. Description: 
  783.  
  784.          This will grab n bytes out of the input buffer and store 
  785.          them in getbuf.  If n bytes are not available, it will 
  786.          return with whatever bytes were available. 
  787.  
  788. Returns: Actual number of bytes grabbed. 
  789.  
  790. Example: 
  791.  
  792.          This is useful for getting blocks of data from the serial 
  793.          port.  Say you wanted to get 131 characters from the input 
  794.          buffer, you could use: 
  795.  
  796.            var buffer   : array [1..131] of byte; 
  797.                received : word; 
  798.  
  799.            begin 
  800.              . . . 
  801.              received:=c_get_stream(com1,buffer,131); 
  802.              if received<131 then 
  803.                writeln('All data not received.') 
  804.              else 
  805.                writeln('Data received.'); 
  806.              . . . 
  807.            end. 
  808.  
  809.          CAUTION:  Make sure you have the correct amount of space 
  810.          reserved for getbuf, or it may overwrite some important data. 
  811.  
  812.  
  813.  
  814. Name:     c_tget_stream 
  815.  
  816. Usage: 
  817.  
  818.           function  c_tget_stream(cp       : porttype; 
  819.                                   var getbuf; 
  820.                                   n, 
  821.                                   timeout  : word       ) : word; 
  822.  
  823. Description: 
  824.  
  825.           This is similar to c_get_stream, except that it will wait 
  826.           timeout hundreds of a second to receive each byte of the 
  827.           data.  This means that if there is no data received within 
  828.           timeout hundreds of a second, it will exit with what it was 
  829.           able to get. 
  830.  
  831. Returns:  Number of bytes received. 
  832.  
  833. Example: 
  834.  
  835.          This is useful for getting blocks of data from the serial 
  836.          port in transfer protocols.  Say you wanted to get 131 
  837.          characters from the input buffer like in c_get_stream, but 
  838.          you wanted it to wait 1 second before it timed out, you would 
  839.          use: 
  840.  
  841.            var buffer   : array [1..131] of byte; 
  842.                received : word; 
  843.  
  844.            begin 
  845.              . . . 
  846.              received:=c_tget_stream(com1,buffer,131,100); 
  847.              if received<131 then 
  848.                writeln('All data not received. Timed out.') 
  849.              else 
  850.                writeln('Data received.'); 
  851.              . . . 
  852.            end. 
  853.  
  854.          CAUTION:  Make sure you have the correct amount of space 
  855.          reserved for getbuf, or it may overwrite some important data. 
  856.  
  857.  
  858.  
  859. Name:    c_put_stream 
  860.  
  861. Usage: 
  862.  
  863.          function  c_put_stream (cp       : porttype; 
  864.                                  var putbuf; 
  865.                                  n        : word     ) : word; 
  866.  
  867. Description: 
  868.  
  869.          This will put n number of characters in putbuf in to the output 
  870.          buffer.  If the output buffer is full, it will just quit. 
  871.  
  872. Returns: Number of characters successfully put in output buffer. 
  873.  
  874. Example: 
  875.  
  876.          This is useful for putting blocks of data to the serial 
  877.          port in transfer protocols.  Say you wanted to send 131 
  878.          characters to the output buffer, you would use: 
  879.  
  880.            var buffer   : array [1..131] of byte; 
  881.                sent     : word; 
  882.  
  883.            begin 
  884.              . . . 
  885.              sent:=c_put_stream(com1,buffer,131); 
  886.              if sent<131 then 
  887.                writeln('All data not sent. Buffer is full.') 
  888.              else 
  889.                writeln('Data sent.'); 
  890.              . . . 
  891.            end. 
  892.  
  893.  
  894.  
  895. Name:     c_XOFF_received 
  896.  
  897. Usage: 
  898.  
  899.           function  c_XOFF_received(cp : porttype ) : boolean; 
  900.  
  901. Description: 
  902.  
  903.           If you are using the built in XON/XOFF checking, this 
  904.           will tell you if you received an XOFF.  This means 
  905.           that the receiver needed to stop transmission. 
  906.  
  907. Returns:  TRUE if an XOFF has been received. 
  908.  
  909. Example: 
  910.           If you know what XON/XOFF is, you probably know what to 
  911.           do with this. 
  912.  
  913.             if c_XOFF_received(com1) then 
  914.               writeln('XOFF received.'); 
  915.  
  916.  
  917.  
  918. Name:     c_XOFF_sent 
  919.  
  920. Usage: 
  921.  
  922.           function  c_XOFF_sent(cp : porttype ) : boolean; 
  923.  
  924. Description: 
  925.  
  926.           If you are using XON/XOFF checking, this tells you if your 
  927.           buffer was overflowing and that you sent and XOFF. 
  928.  
  929. Returns:  TRUE if you needed to send an XOFF. 
  930.  
  931. Example: 
  932.            if c_XOFF_sent(com1) then 
  933.              writeln('JBCOMM sent XOFF to prevent buffer overflow.'); 
  934.  
  935. Name:     c_XON_XOFF 
  936.  
  937. Usage: 
  938.  
  939.           procedure c_XON_XOFF(cp       : porttype; 
  940.                                on       : boolean  ); 
  941.  
  942. Description: 
  943.  
  944.           This enables XON/XOFF data flow control.  XON is ^Q and XOFF is 
  945.           ^S.  If XON/XOFF is enabled, JBCOMM will send an XOFF when the 
  946.           input buffer becomes 75% full, and again when it becomes 90% full 
  947.           in case the first one is not received correctly. 
  948.  
  949.           Send a TRUE for on when you want to turn checking on, and FALSE if 
  950.           you want to disable checking.  Turning it off, then on again will 
  951.           clear the c_XOFF_sent and c_XOFF_received status. 
  952.  
  953. Returns:  Nothing. 
  954.  
  955.  
  956. Example: 
  957.  
  958.           If you are sending data to a printer that supports XON/XOFF, turn 
  959.           it on to make sure you don't lose data. 
  960.  
  961.             c_XON_XOFF(com1,TRUE); 
  962.  
  963.  
  964.  
  965. Name:     c_statusm 
  966.  
  967. Usage: 
  968.  
  969.           function  c_statusm(cp : porttype ) : byte; 
  970.  
  971. Description: 
  972.  
  973.           Gets the contents of the Modem Status Register at last 
  974.           modem status interrupt. 
  975.  
  976.           c_DCTS            = 1;   Delta CTS.  This means that CTS status 
  977.                                    has changed. 
  978.           c_DDSR            = 2;   Delta DSR.  This means that DSR status 
  979.                                    has changed. 
  980.           c_TERI            = 4;   Tail End Ring Indicator.  This tells you 
  981.                                    whether the phone is ringing. 
  982.           c_DRLSD           = 8;   Delta Received Line Signal Detect.  This 
  983.                                    tells you if the carrier status has changed. 
  984.           c_CTS             = 16;  Current status of CTS. 
  985.           c_DSR             = 32;  Current status of DSR. 
  986.           c_RI              = 64;  Current status of Ring Indicator. 
  987.           c_RLSD            = 128; Current Carrier Status. 
  988.  
  989. Returns:  Contents of Modem Status Register. 
  990.  
  991. Example:  None of this is all that useful, but if you need to use it you 
  992.           can check if a certain bit is set by ANDing the CONST you want 
  993.           with the result of c_statusm. 
  994.  
  995.             var result : byte; 
  996.  
  997.             begin 
  998.               . . . 
  999.               result:=c_statusm(com1); 
  1000.               if result and c_RLSD>0 then 
  1001.                 writeln('Carrier was on at last Modem Status Interrupt.'); 
  1002.               . . . 
  1003.             end. 
  1004.  
  1005.  
  1006.  
  1007. Name:     c_statusl 
  1008.  
  1009. Usage: 
  1010.           function  c_statusl(cp : porttype ) : byte; 
  1011.  
  1012. Description: 
  1013.  
  1014.           Gets the contents of the Line Status Register at last 
  1015.           line status register interrupt. 
  1016.  
  1017.           c_DR              = 1;   Data waiting in Receive buffer register. 
  1018.           c_OR              = 2;   Data overun error. 
  1019.           c_PE              = 4;   Parity Error. 
  1020.           c_FE              = 8;   Framing Error. 
  1021.           c_BI              = 16;  Break Interrupt. 
  1022.           c_THRE            = 32;  Transmitter Holding Register empty. 
  1023.           c_TSRE            = 64;  Transmitter Shift Register empty. 
  1024.           c_BO              = 128; Buffer Overflow. 
  1025.  
  1026. Returns:  Value of LSR at last line status interrupt. 
  1027.  
  1028. Example:  None of this is all that useful, but if you need to use it you 
  1029.           can check if a certain bit is set by ANDing the CONST you want 
  1030.           with the result of c_statusl.  The reason this isn't very useful 
  1031.           is that JBCOMM takes care of most of this.  c_OR, c_PE, c_FE, c_BI 
  1032.           and c_BO may be some things you would want to check. 
  1033.  
  1034.             var result : byte; 
  1035.  
  1036.             begin 
  1037.               . . . 
  1038.               result:=c_statusl(com1); 
  1039.               if result and c_BI>0 then 
  1040.                 writeln('Break was sent.'); 
  1041.               . . . 
  1042.             end. 
  1043.  
  1044.  
  1045.  
  1046. Name:     c_lastint 
  1047.  
  1048. Usage: 
  1049.  
  1050.           function  c_lastint(cp : porttype ):byte; 
  1051.  
  1052. Description: 
  1053.  
  1054.           Gets the contents of the interrupt ID register at last interrupt. 
  1055.  
  1056.           c_NONE            = 1;  There was no interrupt. 
  1057.           c_DATA_READY      = 4;  Data came in through serial port. 
  1058.           c_THR_EMPTY       = 2;  Data sent through serial port. 
  1059.           c_LINE_STATUS     = 6;  Line Status has changed. 
  1060.           c_MODEM_STATUS    = 0;  Modem Status has changed. 
  1061.  
  1062. Returns:  Value of Interrupt ID register at last interrupt. 
  1063.  
  1064. Example:  None of this is all that useful, but if you need to use it you 
  1065.           can check if a certain bit is set by ANDing the CONST you want 
  1066.           with the result of c_lastint. 
  1067.  
  1068.             var result : byte; 
  1069.  
  1070.             begin 
  1071.               . . . 
  1072.               result:=c_lastint(com1); 
  1073.               if result and c_DATA_READY>0 then 
  1074.                 writeln('The last interrupt was a data ready interrupt.'); 
  1075.               . . . 
  1076.             end. 
  1077.  
  1078.  
  1079.  
  1080. Name:     c_port_info 
  1081.  
  1082. Usage: 
  1083.  
  1084.           procedure c_port_info(cp       : porttype; 
  1085.                                 var info : com_info_rec); 
  1086.  
  1087. Description: 
  1088.  
  1089.           Returns current status of serial port in a record of type: 
  1090.  
  1091.           com_info_rec = record 
  1092.                            offset,             Base address of serial port.} 
  1093.                            speed   : word;     Current speed setting.      } 
  1094.                            parity  : parityt;  Current Parity Setting. 
  1095.                            data,               Current Data size. 
  1096.                            stops   : byte;     Current Stop bits. 
  1097.                            active,             TRUE if port is active. 
  1098.                            ints_on : boolean   TRUE if interrupts are active. 
  1099.                          end; 
  1100.  
  1101. Returns:  Information in info. 
  1102.  
  1103. Example: 
  1104.           See accompanying program example. 
  1105.  
  1106.  
  1107.  
  1108. Name:     CRC_update 
  1109.  
  1110. Usage: 
  1111.           function  CRC_update(crc      : word; 
  1112.                                b        : byte     ) : word; 
  1113.  
  1114. Description: 
  1115.  
  1116.           Calculates b into a CRC. 
  1117.  
  1118. Returns:  Updated CRC. 
  1119.  
  1120. Example: 
  1121.           This is for doing Xmodem CRC transfers. 
  1122.  
  1123.             var CRC    : word; 
  1124.                 buffer : array [1..128] of byte; 
  1125.                 i      : word; 
  1126.             begin 
  1127.               . . . 
  1128.               CRC:=0; 
  1129.               for i:=1 to 128 do CRC:=CRC_update(CRC,buffer[i]); 
  1130.               CRC:=CRC_update(CRC,0); 
  1131.               CRC:=CRC_update(CRC,0); 
  1132.               . . . {CRC now contains the CRC of the 128 byte block.} 
  1133.             end. 
  1134.  
  1135.  
  1136.  
  1137. Name:     block_CRC 
  1138.  
  1139. Usage: 
  1140.  
  1141.           function  block_CRC(var block; 
  1142.                               n        : word ) : word; 
  1143.  
  1144. Description: 
  1145.  
  1146.           Calculates a CRC for n bytes of memory starting with block. 
  1147.  
  1148. Returns:  CRC for n bytes of memory pointed to by block. 
  1149.  
  1150. Example: 
  1151.           This is for doing Xmodem CRC transfers.  block_CRC does the 
  1152.           same as the example for CRC_update. 
  1153.  
  1154.             var CRC    : word; 
  1155.                 buffer : array [1..128] of byte; 
  1156.                 i      : word; 
  1157.             begin 
  1158.               . . . 
  1159.               CRC:=block_CRC(buffer,128); 
  1160.               . . . {CRC now contains the CRC of the 128 byte block.} 
  1161.             end. 
  1162.  
  1163.  
  1164.  
  1165.